package com.kaizeli.website.controller;

import com.kaizeli.website.pojo.entity.ProjectAcceptance;
import com.kaizeli.website.pojo.dto.ProjectAcceptanceDTO;
import com.kaizeli.website.service.ProjectAcceptanceService;
import com.kaizeli.website.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目验收单控制器
 */
@RestController
@RequestMapping("/api/project-acceptance")
@CrossOrigin(origins = "*")
public class ProjectAcceptanceController {

    @Autowired
    private ProjectAcceptanceService projectAcceptanceService;

    /**
     * 根据项目ID查询验收单列表
     */
    @GetMapping("/project/{projectId}")
    public Result<List<ProjectAcceptanceDTO>> getAcceptanceByProject(@PathVariable Long projectId) {
        return projectAcceptanceService.getAcceptanceByProjectId(projectId);
    }

    /**
     * 根据验收单ID查询验收单详情
     */
    @GetMapping("/{id}")
    public Result<ProjectAcceptanceDTO> getAcceptanceById(@PathVariable Long id) {
        return projectAcceptanceService.getAcceptanceById(id);
    }

    /**
     * 创建验收单
     */
    @PostMapping
    public Result<ProjectAcceptance> createAcceptance(@RequestBody ProjectAcceptance acceptance) {
        return projectAcceptanceService.createAcceptance(acceptance);
    }

    /**
     * 更新验收单
     */
    @PutMapping("/{id}")
    public Result<Void> updateAcceptance(@PathVariable Long id, @RequestBody ProjectAcceptance acceptance) {
        return projectAcceptanceService.updateAcceptance(id, acceptance);
    }

    /**
     * 更新验收单状态
     */
    @PutMapping("/{id}/status")
    public Result<Void> updateAcceptanceStatus(@PathVariable Long id, @RequestParam String status) {
        return projectAcceptanceService.updateAcceptanceStatus(id, status);
    }

    /**
     * 删除验收单
     */
    @DeleteMapping("/{id}")
    public Result<Void> deleteAcceptance(@PathVariable Long id) {
        return projectAcceptanceService.deleteAcceptance(id);
    }

    /**
     * 提交验收单
     */
    @PostMapping("/{id}/submit")
    public Result<Void> submitAcceptance(@PathVariable Long id) {
        return projectAcceptanceService.submitAcceptance(id);
    }

    /**
     * 审核验收单
     */
    @PostMapping("/{id}/review")
    public Result<Void> reviewAcceptance(@PathVariable Long id, 
                                       @RequestParam String status, 
                                       @RequestParam(required = false) String remark) {
        return projectAcceptanceService.reviewAcceptance(id, status, remark);
    }

    /**
     * 完成验收单
     */
    @PostMapping("/{id}/complete")
    public Result<Void> completeAcceptance(@PathVariable Long id) {
        return projectAcceptanceService.completeAcceptance(id);
    }

    /**
     * 更新验收单完成时间
     */
    @PutMapping("/{id}/completion-time")
    public Result<Void> updateAcceptanceCompletionTime(@PathVariable Long id, 
                                                       @RequestParam String completionTime) {
        return projectAcceptanceService.updateAcceptanceCompletionTime(id, completionTime);
    }
}